package com.focus.xyz.union.data;


import com.focus.xyz.core.utils.Constants;
import com.focus.xyz.core.utils.ExcelUtils;
import com.focus.xyz.core.utils.prop.ConfigPropInfo;
import org.apache.poi.ss.usermodel.Row;

import java.util.Arrays;
import java.util.List;

/**
 * Created by chenmeng on 2016/5/6.
 */
public class InsDataService {
    private static ExcelUtils eu;

    static {
        eu = new ExcelUtils(ConfigPropInfo.TEST_DATA_DIR + ConfigPropInfo.TEST_UNION_DATA_FILE);
        eu.setStartReadPos(1);
        eu.setOnlyReadOneSheet(true);
    }


    /*
    * 根据序号查询被保人数据
    * */
    public static List<InsuredBean> getInsuredById(String[] ids) throws Exception{
        int[] aa = new int[ids.length];
        for(int i = 0;i<ids.length;i++){
            aa[i] = Integer.valueOf(ids[i]);
        }
        eu.setSelectedSheetName(Constants.INSURED);
        List<Row> rows = eu.getRowsByIndex(aa);
        InsuredBean[] insureds = new InsuredBean[rows.size()];
        for (int i = 0;i<rows.size();i++){
            insureds[i] = new InsuredBean();
            insureds[i].setDev_name((eu.getCellValue(rows.get(i).getCell(1))));
            insureds[i].setDev_engName((eu.getCellValue(rows.get(i).getCell(2))));
            insureds[i].setDev_cardType((eu.getCellValue(rows.get(i).getCell(3))));
            insureds[i].setDev_cardNo((eu.getCellValue(rows.get(i).getCell(4))));
            insureds[i].setDev_birthday((eu.getCellValue(rows.get(i).getCell(5))));
            insureds[i].setDev_gender((eu.getCellValue(rows.get(i).getCell(6))));
            insureds[i].setDev_jobs((eu.getCellValue(rows.get(i).getCell(12))));
            insureds[i].setDev_mobile((eu.getCellValue(rows.get(i).getCell(13))));
            insureds[i].setDev_insurantType((eu.getCellValue(rows.get(i).getCell(14))));

        }
        return Arrays.asList(insureds);
    }

    /*
    * 根据需要查询投保计划
    * */
    public static InsPlanBean getInsPlanById(String id) throws Exception{
        eu.setSelectedSheetName(Constants.INS_PLAN);
        int[] aa = {Integer.valueOf(id)};
        List<Row> rows = eu.getRowsByIndex(aa);
        InsPlanBean[] insPlanBeans = new InsPlanBean[rows.size()];
        for (int i = 0;i<rows.size();i++){
            insPlanBeans[i] = new InsPlanBean();
            insPlanBeans[i].setDev_period((eu.getCellValue(rows.get(i).getCell(1))));
            insPlanBeans[i].setDestination(eu.getCellValue(rows.get(i).getCell(2)));
            insPlanBeans[i].setDev_startTime((eu.getCellValue(rows.get(i).getCell(3))));
            insPlanBeans[i].setDev_endTime((eu.getCellValue(rows.get(i).getCell(4))));
        }
        return insPlanBeans[0];
    }

    /*
    * 根据序号查询投保人数据
    * */
    public static ApplicantBean getApplicantById(String id) throws Exception{
        eu.setSelectedSheetName(Constants.INS_APPLICANT);
        int[] aa = {Integer.valueOf(id)};
        List<Row> rows = eu.getRowsByIndex(aa);
        ApplicantBean[] ab = new ApplicantBean[rows.size()];
        for (int i = 0;i<rows.size();i++){
            ab[i] = new ApplicantBean();
            ab[i].setDev_insAppDtoName((eu.getCellValue(rows.get(i).getCell(1))));
            ab[i].setDev_insAppDtoCardType((eu.getCellValue(rows.get(i).getCell(2))));
            ab[i].setDev_insAppDtoCardNo((eu.getCellValue(rows.get(i).getCell(3))));
            ab[i].setDev_insAppDtoProvince(eu.getCellValue(rows.get(i).getCell(4)));
            ab[i].setDev_insAppDtoCity((eu.getCellValue(rows.get(i).getCell(5))));
            ab[i].setDev_insAppDtoMobile((eu.getCellValue(rows.get(i).getCell(6))));
            ab[i].setDev_insAppDtoEmail((eu.getCellValue(rows.get(i).getCell(7))));
            ab[i].setGender((eu.getCellValue(rows.get(i).getCell(8))));
            ab[i].setDev_appBirthday((eu.getCellValue(rows.get(i).getCell(9))));

        }
        return ab[0];
    }


    /*
    * 根据序号查询子账号数据
    * */
    public static SubAcctBean getSubInfoById(String subId) throws Exception{
        eu.setSelectedSheetName(Constants.INS_SUB);
        int[] aa = {Integer.valueOf(subId)};
        List<Row> rows = eu.getRowsByIndex(aa);
        SubAcctBean[] ab = new SubAcctBean[rows.size()];
        for (int i = 0;i<rows.size();i++){
            ab[i] = new SubAcctBean();
            ab[i].setLoginName((eu.getCellValue(rows.get(i).getCell(1))));
            ab[i].setLoginPwd((eu.getCellValue(rows.get(i).getCell(2))));
            ab[i].setContactName((eu.getCellValue(rows.get(i).getCell(3))));
            ab[i].setLoginEmail(eu.getCellValue(rows.get(i).getCell(4)));
            ab[i].setLoginMobile((eu.getCellValue(rows.get(i).getCell(5))));
            ab[i].setLoginTel((eu.getCellValue(rows.get(i).getCell(6))));
            ab[i].setAgentDesc((eu.getCellValue(rows.get(i).getCell(7))));
        }
        return ab[0];
    }


    /*
    * 根据序号查询投保数据
    * */
    public static InsDataBean getInsDataById(String index) throws Exception{
        eu.setSelectedSheetName(Constants.INS_DATA);
        int[] aa = {Integer.valueOf(index)};
        List<Row> rows = eu.getRowsByIndex(aa);
        InsDataBean[] ab = new InsDataBean[rows.size()];
        for (int i = 0;i<rows.size();i++){
            ab[i] = new InsDataBean();
            ab[i].setId((eu.getCellValue(rows.get(i).getCell(0))));
            ab[i].setType((eu.getCellValue(rows.get(i).getCell(1))));
            ab[i].setProdName((eu.getCellValue(rows.get(i).getCell(2))));
            ab[i].setPlanId(eu.getCellValue(rows.get(i).getCell(3)));
            ab[i].setInsuredId((eu.getCellValue(rows.get(i).getCell(4))));
            ab[i].setApplicantId((eu.getCellValue(rows.get(i).getCell(5))));
            ab[i].setDesc((eu.getCellValue(rows.get(i).getCell(6))));
            ab[i].setExpectedPrice((eu.getCellValue(rows.get(i).getCell(7))));
        }
        return ab[0];
    }

    public static WebSiteBean getWebSiteById(String index) throws Exception{
        eu.setSelectedSheetName(Constants.INS_WS);
        int[] aa = {Integer.valueOf(index)};
        List<Row> rows = eu.getRowsByIndex(aa);
        WebSiteBean[] ab = new WebSiteBean[rows.size()];
        for (int i = 0;i<rows.size();i++){
            ab[i] = new WebSiteBean();
            ab[i].setWebName((eu.getCellValue(rows.get(i).getCell(1))));
            ab[i].setWebUrl((eu.getCellValue(rows.get(i).getCell(2))));
            ab[i].setWebType((eu.getCellValue(rows.get(i).getCell(3))));
            ab[i].setWebIntro(eu.getCellValue(rows.get(i).getCell(4)));
            String platType = eu.getCellValue(rows.get(i).getCell(5));
            if("PC端".equals(platType)){
                ab[i].setPlatformType_pc("Y");
            }else{
                ab[i].setPlatformType_mobile("Y");
            }
            ab[i].setWebIcp((eu.getCellValue(rows.get(i).getCell(6))));
        }
        return ab[0];
    }

    public static ApiBean getApiById(String idx) throws Exception{
        eu.setSelectedSheetName(Constants.INS_WS);
        int[] aa = {Integer.valueOf(idx)};
        List<Row> rows = eu.getRowsByIndex(aa);
        ApiBean[] ab = new ApiBean[rows.size()];
        for (int i = 0;i<rows.size();i++){
            ab[i] = new ApiBean();
            ab[i].setContactName((eu.getCellValue(rows.get(i).getCell(8))));
            ab[i].setEmail((eu.getCellValue(rows.get(i).getCell(9))));
            ab[i].setPhone((eu.getCellValue(rows.get(i).getCell(10))));
            ab[i].setUseSpectacle(eu.getCellValue(rows.get(i).getCell(11)));
        }
        return ab[0];
    }
}
